home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
bipl.zip
/
PROCS.ZIP
/
TEMPNAME.ICN
< prev
next >
Wrap
Text File
|
1992-09-28
|
2KB
|
58 lines
############################################################################
#
# File: tempname.icn
#
# Subject: Procedure to get temporary file name
#
# Author: Richard L. Goerwitz
#
# Date: June 1, 1991
#
###########################################################################
#
# Version: 1.5
#
###########################################################################
#
# Need to open up a temporary file? This procedure prevents you from
# clobbering existing files by giving you a unique temp file name.
# Note that tempname() does not return an open file. It merely returns
# a string. The user is responsible for open()'ing a file by that
# name, and for removing it when done.
#
# Note that tempname() is a generator, suspending upto 999 unique
# (and MS-DOS compatible) filenames.
#
# Bug: Icon has no exists() call, so the only way we can tell if a
# filename is already in use is to try to open it for reading. On
# most systems, inability to read a file by a given name does not
# necessarily indicate that the filename is not in use. Hence this
# procedure may, under very, very rare circumstances, return the
# name of a file already in use. We're safe, though, since if this
# ever happens to anyone (which I doubt), no files will get clob-
# bered. One workaround for the problem is to call tempname() with-
# out using any intermediate variables, so that it is resumed until
# some open function succeeds (e.g. open(tempname())).
#
############################################################################
#
# Requires: UNIX, MS-DOS or another congenial operating system
#
############################################################################
procedure tempname()
static dir
initial {
if find("UNIX",&features) then
dir := "/tmp/"
else dir := ""
}
every temp_name := dir || "icontmp." || right(1 to 999,3,"0") do {
close(open(temp_name)) & next
suspend \temp_name
}
end